import * as actionTypes from '../constants/header';

import {fromJS} from 'immutable';

const defaultState = fromJS({
    focused: false,
    mouseIn: false,
    page: 1,
    totalPage: 1,
    list: []
});

export default (state = defaultState, action) => {

    switch (action.type) {

        case actionTypes.SEARCH_FOCUS:
            return state.set('focused', true);

        case actionTypes.SEARCH_BLUR:
            return state.set('focused', false);

        case actionTypes.CHANGE_LIST:
            return state.set('list', action.data).set('totalPage', action.totalPage);

        case actionTypes.MOUSE_ENTER:
            return state.set('mouseIn', true);

        case actionTypes.MOUSE_LEAVE:
            return state.set('mouseIn', false);

        case actionTypes.CHANGE_LIST_PAGE:
            return state.set('page', action.page);

        default:
            return state;

    }

}